package com.xh.web.service.impl;


import com.xh.web.domain.DContent;
import com.xh.web.mapper.DContentMapper;
import com.xh.web.service.IDContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 目录Service业务层处理
 *
 * @author fulan
 * @date 2020-09-16
 */
@Service
public class DContentServiceImpl implements IDContentService
{
    @Autowired(required = false)
    private DContentMapper dContentMapper;

    /**
     * 查询目录列表
     *
     * @param dContent
     * @return 目录
     */
    @Override
    public List<DContent> selectDContentList(DContent dContent)
    {
        return dContentMapper.selectDContentList(dContent);
    }

    /**
     * 新增目录
     *
     * @param dContent 目录
     * @return
     */
    @Override
    public int insertDContent(String projectId,DContent dContent)
    {

        dContent.setProjectId(projectId);
        dContent.setdSort((long) 1);
        //SysUser user = SecurityUtils.getLoginUser().getUser();
        dContent.setCreateBy("admin");
        dContent.setCreateName("admin");
        dContent.setCreateDate(new Date());
        dContent.setUpdateBy("admin");
        dContent.setUpdateDate(new Date());
        dContent.setDelFlag("0");
        if (dContent.getParentId()!=null){
           DContent dContent1= dContentMapper.selectDContentById(dContent.getParentId());
                dContent.setParentName(dContent1.getContentName());
        }
        return dContentMapper.insertDContent(dContent);
    }

    /**
     * 修改目录
     *
     * @return 结果
     */
    @Override
    public int updateDContent(DContent dContent)
    {

        //SysUser user = SecurityUtils.getLoginUser().getUser();
        dContent.setUpdateBy("admin");
        dContent.setUpdateDate(new Date());
        return dContentMapper.updateDContent(dContent);
    }

    //根据parentId查询子目录
    public List<DContent> selectDContentByParentId(String id){return dContentMapper.selectDContentByParentId(id);}

    /**
     * 删除目录信息
     *
     * @param id 目录ID
     * @return 结果
     */
    @Override
    public int deleteDContentById(String id)
    {
        return dContentMapper.deleteDContentById(id);
    }
}
